package com.myh.cc.coom.recommend.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.myh.cc.coom.recommend.bean.RecommendBean
import com.myh.cc.databinding.ItemRevommendRvBinding
import com.myh.cc.widget.OnItemClickListener

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/12.
 */
class RecommendAdapter(bean: RecommendBean,context: Context): RecyclerView.Adapter<RecommendAdapter.VH>(){


    val bean = bean
    val context = context
    var mListener: OnItemClickListener? = null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return VH.create(LayoutInflater.from(parent.context), parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int) {

        var list = bean.data.albumlist

        val picUrl = "http://y.gtimg.cn/music/photo_new/T002R300x300M000"+list[position].album_mid+".jpg?max_age=2592000"

        Glide.with(context).load(picUrl).into(holder.binding.itemIvIcon)

        holder.binding.itemTvMusic.text = list[position].album_name

        holder.binding.itemTvName.text = list[position].singers[0].singer_name

        holder.binding.itemTvTime.text = list[position].public_time

        holder.binding.root.setOnClickListener { view ->
            mListener?.onClick(view,position)
        }
    }

    override fun getItemCount(): Int {

        return bean.data.albumlist.size
    }



    class VH constructor(binding: ItemRevommendRvBinding): RecyclerView.ViewHolder(binding.root){

        val  binding = binding


        companion object {
            fun create(inflater: LayoutInflater, parent: ViewGroup): VH {
                val binding = ItemRevommendRvBinding.inflate(inflater, parent, false)
                return VH(binding)
            }
        }



    }



}


